const bodyParser = require('body-parser')
const express = require('express')
const mongoose = require('mongoose')
const path = require('path')
const app = express()

app.use(express.static('public'))
app.use(bodyParser.urlencoded({extended:false}))
app.use(bodyParser.json())
 //开放node_modules
app.use('/node_modules',express.static(path.join(__dirname,'./node_modules')))
//路由器中间件
const indexRouter = require('./routes')
app.use('/',indexRouter)
//链接数据库
mongoose.connect('mongodb://localhost/sms-service',{useNewUrlParser:true}).then(()=>{
    console.log("链接成功");
    app.listen('3000',()=>{
        console.log("启动成功 访问http://localhost:3000");
    })
}).catch(err=>{
    console.log("链接失败");
});